/**********************************************************
 * UserRegistrationOptionsDelegator.java.java
 * Created by Ashutosh
 * Last modified Date: Sep 18, 2008 10:56:12 AM by Ashutosh
 * Revision: <svn revision #>
 * Version : 0.1
 * Copyright (c) 2008 - 2009 cyberThink Infotech Pvt. Ltd., All rights reserved.
 **********************************************************/

package com.printeverywhere.delegator;

import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.printeverywhere.dto.UserRegistrationOptions;
import com.printeverywhere.util.AdminConstants;
import com.printeverywhere.util.HibernateUtil;

/**
 * The Class UserRegistrationOptionsDelegator.
 */
public class UserRegistrationOptionsDelegator {

  	/**
  	 * Gets the list.
  	 *
  	 * @return the list
  	 *
  	 * @throws HibernateException the hibernate exception
  	 */
  	public static List<UserRegistrationOptions> getList() throws HibernateException {
          Session session = HibernateUtil.getSession();
          try{
        	  session.beginTransaction();
              List<UserRegistrationOptions> list = session.createCriteria(UserRegistrationOptions.class).list();
              return list;
          }catch(HibernateException e){
              e.printStackTrace();
              throw e;
          }finally{
        	  session.flush();
              session.close();
          }
}

	  /**
  	 * Adds the.
  	 *
  	 * @param userRegistration the user registration
  	 *
  	 * @return the string
  	 *
  	 * @throws HibernateException the hibernate exception
  	 */
  	public static String add(UserRegistrationOptions userRegistration) throws HibernateException{
          Session session = HibernateUtil.getSession();
          Transaction transaction = session.beginTransaction();
          try {
                      session.save(userRegistration);
                      transaction.commit();
          } catch (HibernateException e) {
                      transaction.rollback();
                      throw e;
          }finally{
                      session.close();
          }
          return AdminConstants.RECORD_ADDED;
  	}

	  /**
  	 * Update.
  	 *
  	 * @param userRegistration the user registration
  	 *
  	 * @return the string
  	 *
  	 * @throws HibernateException the hibernate exception
  	 */
  	public static String update(UserRegistrationOptions userRegistration) throws HibernateException{
          Session session = HibernateUtil.getSession();
          Transaction transaction = session.beginTransaction();
          try {
        	  	session.update(userRegistration);
        	  	transaction.commit();
          } catch (HibernateException e) {
                      transaction.rollback();
                      throw e;
          }finally{
                      session.close();
          }
          return AdminConstants.RECORD_UPDATED;
  	}
}